﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Nova_DAL;
using System.Data.Common;

public partial class Manage_Bill_List : System.Web.UI.Page
{
    DbHelper access = new DbHelper();
    DbCommand cmd = null;
    string strSQL = "";

    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            gv_Bind();
        }
    }

    protected string getSQL()
    {
        HttpCookie WType = Request.Cookies["WType"];

//        strSQL = @"SELECT TBA.StockNo,MAX(CONVERT(varchar(100), TBA.CDT, 23))AS CDT FROM TBill_AddStorage TBA LEFT JOIN TAddStorage_List TAL ON TAL.StockNo=TBA.StockNo
// WHERE TBA.Bill_Status=0  AND (TAL.TS02 = '" + WType.Value.ToString().Trim() + "' OR 'FSSC'='" + WType.Value.ToString().Trim() + "')  ";
        //谢刚伟修改
        strSQL = @"SELECT TBA.StockNo,MAX(CONVERT(varchar(100), TBA.CDT, 23))AS CDT FROM TBill_AddStorage TBA LEFT JOIN TAddStorage_List TAL ON TAL.StockNo=TBA.StockNo
 WHERE TBA.Bill_Status=0 ";


        if (txt_Stock_No.Text != "")
        {
            strSQL += " AND TBA.StockNo LIKE '%" + txt_Stock_No.Text.Trim() + "%'";
        }
        strSQL += " GROUP BY TBA.StockNo ORDER BY TBA.StockNo DESC";
        return strSQL;
    }

    protected void gv_Bind()
    {
        cmd = access.GetSqlStringCommond(getSQL());
        gv.DataSource = access.ExecuteDataSet(cmd);
        gv.DataBind();
    }

    protected void ibtnSearch_Click(object sender, ImageClickEventArgs e)
    {
        gv_Bind();
    }

    protected void gv_PageIndexChanging(object sender, GridViewPageEventArgs e)
    {
        gv.PageIndex = e.NewPageIndex;
        gv_Bind();  //重新绑定GridView
    }
    protected void gv_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowType == DataControlRowType.DataRow)
        {
            Label LabStock_No = (Label)e.Row.Cells[1].FindControl("LabStock_No");

            Label LabNumber = (Label)e.Row.Cells[1].FindControl("LabNumber");

          //  e.Row.Attributes.Add("onclick", "parent.window.returnValue='" + LabNumber.Text.Trim() + "," + LabStock_No.Text.Trim() + "," + e.Row.Cells[2].Text.Trim().Replace("&nbsp;", "") + "';parent.window.close();");

            e.Row.Attributes.Add("onclick", "window.parent.opener.document.getElementById('txt_StorageNo').value='" + LabStock_No.Text.ToString() + "';parent.window.close();");

            //鼠标移动到每项时颜色交替效果   
            e.Row.Attributes.Add("OnMouseOut", "this.style.backgroundColor='White';this.style.color='#003399'");
            e.Row.Attributes.Add("OnMouseOver", "this.style.backgroundColor='#6699FF';this.style.color='#8C4510'");

            //设置悬浮鼠标指针形状为"小手"   
            e.Row.Attributes["style"] = "Cursor:hand";
        }
    }

    protected void ibrn_S_Click(object sender, ImageClickEventArgs e)
    {
        cmd = access.GetSqlStringCommond(getSQL());
        gv.DataSource = access.ExecuteDataSet(cmd);
        gv.DataBind();
    }
}